package com.spvs.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.spvs.common.log.annotation.Log;
import com.spvs.common.log.enums.BusinessType;
import com.spvs.common.security.annotation.RequiresPermissions;
import com.spvs.system.domain.FileView;
import com.spvs.system.service.IFileViewService;
import com.spvs.common.core.web.controller.BaseController;
import com.spvs.common.core.web.domain.AjaxResult;
import com.spvs.common.core.utils.poi.ExcelUtil;
import com.spvs.common.core.web.page.TableDataInfo;

/**
 * 文件查看Controller
 *
 * @author supervision
 * @date 2024-12-12
 */
@RestController
@RequestMapping("/view")
public class FileViewController extends BaseController
{
    @Autowired
    private IFileViewService fileViewService;

    /**
     * 查询文件查看列表
     */
    @RequiresPermissions("system:view:list")
    @GetMapping("/list")
    public TableDataInfo list(FileView fileView)
    {
        startPage();
        List<FileView> list = fileViewService.selectFileViewList(fileView);
        return getDataTable(list);
    }

    /**
     * 导出文件查看列表
     */
    @RequiresPermissions("system:view:export")
    @Log(title = "文件查看", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FileView fileView)
    {
        List<FileView> list = fileViewService.selectFileViewList(fileView);
        ExcelUtil<FileView> util = new ExcelUtil<FileView>(FileView.class);
        util.exportExcel(response, list, "文件查看数据");
    }

    /**
     * 获取文件查看详细信息
     */
    @RequiresPermissions("system:view:query")
    @GetMapping(value = "/{viewId}")
    public AjaxResult getInfo(@PathVariable("viewId") Long viewId)
    {
        return success(fileViewService.selectFileViewByViewId(viewId));
    }

    /**
     * 新增文件查看
     */
    @RequiresPermissions("system:view:add")
    @Log(title = "文件查看", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FileView fileView)
    {
        return toAjax(fileViewService.insertFileView(fileView));
    }

    /**
     * 修改文件查看
     */
    @RequiresPermissions("system:view:edit")
    @Log(title = "文件查看", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FileView fileView)
    {
        return toAjax(fileViewService.updateFileView(fileView));
    }

    /**
     * 删除文件查看
     */
    @RequiresPermissions("system:view:remove")
    @Log(title = "文件查看", businessType = BusinessType.DELETE)
	@DeleteMapping("/{viewIds}")
    public AjaxResult remove(@PathVariable Long[] viewIds)
    {
        return toAjax(fileViewService.deleteFileViewByViewIds(viewIds));
    }
}
